import axios from './axios';
import qs from 'qs'

export function showInvoice() {
    return axios.get('/spare_parts_export/manage/show_invoice.do').then(res => {
        return Promise.resolve(res.data)
    }, err => {
        return Promise.reject(err)
    })
}

export function getBoxList(pageNum, contractNumber) {
    return axios.get(`/packing/manage/show_packing_order_list.do?pageNum=${pageNum}&contractNumber=${contractNumber}`)
        .then(res => Promise.resolve(res.data))
}

export function addBoxList(box) {
    return axios.post('/packing/manage/add_packing_order.do', qs.stringify(box))
        .then(res => Promise.resolve(res.data))
}

export function modBoxList(box) {
    return axios.post('/packing/manage/update_packing_order.do', qs.stringify(box))
        .then(res => Promise.resolve(res.data))
}

export function getConsignmentDetail(consignmentOrderId) {
    return axios.get(`/packing/manage/show_consignment_order_detail.do?consignmentOrderId=${consignmentOrderId}`)
        .then(res => Promise.resolve(res.data))
}

export function getBoxListDetail(packingOrderId) { //获取装箱单的详情
    return axios.get(`/packing/manage/show_packing_order_detail.do?packingOrderId=${packingOrderId}`)
        .then(res => Promise.resolve(res.data));
}

//根据寄售合同和发运批次来查询装箱详情统计
export function getAllPackListReport({consignmentOrderId, batch}) {
    return axios.post('/packing/manage/packing_order_statistics.do', qs.stringify({
        consignmentOrderId,
        batch
    })).then(res => Promise.resolve(res.data));
}

//发运合同查询箱单详情
export function getAllPackListDetail(consignmentId, batch) {
    return axios.post('/send_goods/manage/select_by_consignment_id_and_batch.do', qs.stringify({
        consignmentId,
        batch
    })).then(res => Promise.resolve(res.data));
}

//根据船查询入库状态
export function getStockInfoByShip(shipInformation) {
    return axios.get(`/packing/manage/check_stock_ot_not.do?shipInformation=${shipInformation}`)
        .then(res => Promise.resolve(res.data))
}

//查询未发运的配件
export function getUndeliveryPart(id) {
    return axios.post('/import_and_export/manage/show_un_send_quantity.do', qs.stringify({consignmentOrderId: id}))
        .then(res => Promise.resolve(res.data))
}

//展示所有周
export function getWeek() {
    return axios.get('/week/statistical_report/show_all_week.do').then(res => Promise.resolve(res.data))
}

export function getWeekReport(week) {
    return axios.get(`/week/statistical_report/show_week_statistical_report.do?statisticalReportDate=${week}`)
        .then(res => Promise.resolve(res.data))
}

//获取图表数据(销售)
export function getChartSaleData({ year,warehouse, belongModule}) {
    let url;
    if (warehouse && belongModule) {
        url = `/statistic_chart/manage/statistic_cart_year.do?year=${year}&belongModule=${belongModule}&warehouse=${warehouse}`
    }
    else if (warehouse && !belongModule) {
        url = `/statistic_chart/manage/statistic_cart_year.do?year=${year}&warehouse=${warehouse}`
    } else if (belongModule && !warehouse) {
        url = `/statistic_chart/manage/statistic_cart_year.do?year=${year}&belongModule=${belongModule}`
    }
    return axios.get(url)
        .then(res => Promise.resolve(res.data))
}

//获取数据表格 饼图
export function getUseRatePieChart(belongModule,warehouse) {
    return axios.get('/statistic_chart/manage/in_stock_percentage_optimization.do',{
        params:{
            belongModule,
            warehouse
        }
    }).then(res => Promise.resolve(res.data))
}

//获取配件出库图表
export function stockOutChart({partsId, belongModule, warehouse}) {
    return axios.post('/statistic_chart/manage/out_quantity_statistic_by_month.do', qs.stringify({
        partsId,
        belongModule,
        warehouse
    }))
        .then(res => Promise.resolve(res.data))

}

export function getLineChart({ warehouse, belongModule}) {
    let url;
    if (warehouse && belongModule) {
        url = `/statistic_chart/manage/statistics_every_day_inventory_price.do?belongModule=${belongModule}&warehouse=${warehouse}`
    }
    else if (warehouse && !belongModule) {
        url = `/statistic_chart/manage/statistics_every_day_inventory_price.do?warehouse=${warehouse}`
    } else if (belongModule && !warehouse) {
            url = `/statistic_chart/manage/statistics_every_day_inventory_price.do?belongModule=${belongModule}`
    } else {
        url = '/statistic_chart/manage/statistics_every_day_inventory_price.do'
    }
    return axios.get(url)
        .then(res => Promise.resolve(res.data))
}

export function getChartDataByShip() {
    return axios.get('/spare_parts_export/manage/ship_statistics.do').then(res => Promise.resolve(res.data))
}

export function getPartStockOutOrderByCustomer({partsId, year, month, belongModule, warehouse}) {
    return axios.post('/optimization_inventory/manage/out_quantity_group_by_customer.do'
        ,qs.stringify({partsId, year, month, belongModule, warehouse})).then(res => Promise.resolve(res.data))

}

export function getConsignmentTime(consignmentOrderId) {
    return axios.post(`/import_and_export/manage/show_send_order_by_consignment_order_id.do?consignmentOrderId=${consignmentOrderId}`)
        .then(res => Promise.resolve(res.data))
}